package com.chinaztt.fda.test.RecyclerPullPackage;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chinaztt.fda.test.RecyclerPullPackage.base.BaseListActivity;
import com.chinaztt.fda.test.RecyclerPullPackage.model.Module;
import com.chinaztt.fda.test.RecyclerPullPackage.sample.SampleListActivity;
import com.chinaztt.fda.test.RecyclerPullPackage.sample.SampleListFragmentActivity;
import com.chinaztt.fda.test.RecyclerPullPackage.sample.SampleSectionListActivity;
import com.chinaztt.fda.test.RecyclerPullPackage.sample.SampleSectionListFragmentActivity;
import com.chinaztt.fda.test.RecyclerPullPackage.weigit.pull.BaseViewHolder;
import com.chinaztt.fda.ui.R;

import java.util.ArrayList;

/**
 * @Description 下拉刷新recycleview封装
 * @Creator wushan
 * @Date 2016/4/21 15:29
 */
public class PullHomeActivity extends BaseListActivity<Module> {

    @Override
    protected void setUpTitle(int titleResId) {
        super.setUpTitle(R.string.title_framework_main);
    }

    @Override
    protected void setUpData() {
        super.setUpData();
        recycler.enablePullToRefresh(false);
        recycler.setRefreshing();
    }

    @Override
    protected BaseViewHolder getViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_home_item,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onRefresh(int action) {
        mDataList = new ArrayList<>();
        mDataList.add(new Module("RecyclerView基于BaseListActivity\n支持下拉刷新,加载更多", SampleListActivity.class));
        mDataList.add(new Module("RecyclerView基于BaseListFragment\n支持下拉刷新,加载更多", SampleListFragmentActivity.class));
        mDataList.add(new Module("RecyclerView基于BaseSectionListActivity\n支持分组,下拉刷新,加载更多", SampleSectionListActivity.class));
        mDataList.add(new Module("RecyclerView基于BaseSectionListFragment\n支持分组,下拉刷新,加载更多", SampleSectionListFragmentActivity.class));
        recycler.onRefreshCompleted();
    }

    private class ViewHolder extends BaseViewHolder {

        private final TextView mHomeItemModuleLabel;

        public ViewHolder(View itemView) {
            super(itemView);
            this.mHomeItemModuleLabel = (TextView) itemView.findViewById(R.id.mHomeItemModuleLabel);
        }

        @Override
        public void onBindViewHolder(int position) {
            mHomeItemModuleLabel.setText(mDataList.get(position).moduleName);
        }

        @Override
        public void onItemClick(View view, int position) {
            startActivity(new Intent(PullHomeActivity.this, mDataList.get(position).moduleTargetClass));
        }
    }
}